<?php
namespace Admin\Controller;
class TeamworkController extends BaseController {
    public function index(){
         $count = M('collaboration')->count();
        $this->assign('count',$count);
    	$arr=M('collaboration')->select();
    	$this->assign('arr',$arr);
        $this->display();
    }
    public function adddo(){
    	//dump($_POST);
    	$_POST['addtime']=time();
    	$res=M('collaboration')->add($_POST);
    	if($res){
    		$this->success('添加成功');
    	}else{
    		$this->error('添加失败');
    	}
    }
        //修改图片
    public function edit(){
        $data=M('collaboration')->where($_POST)->find();
        $this->assign('data',$data);
        $this->display();
    }
    //删除
    public function del(){
       $res=M('collaboration')->where($_POST)->delete();
       if($res){
        $this->ajaxReturn(1);
       }else{
        $this->ajaxReturn(0);
       }
    }
    //修改状态
   	public function status(){
   		$result=M('collaboration')->save($_POST);
   		if($result){
   			$this->ajaxReturn(1);
   		}else{
   			$this->ajaxReturn(0);
   		}
   	}
         public function add_photo(){
        $upload = new \Think\Upload();                                          // 实例化上传类
        $upload->maxSize = 1024*1024*10 ;                                       // 设置附件上传大小
        $upload->exts = array('jpg', 'gif', 'png', 'jpeg');                     // 设置附件上传类型
        $upload->rootPath = 'Public/';                                       // 设置附件上传根目录
        $upload->savePath = 'admin/Uploads/images/';
        $info = $upload->uploadOne($_FILES['img']);
        if($info){
            $res['messsge']=$upload->getError();
            $res['result_code'] = 100;
            $res['file'] = '/public/'.$info['savepath'].$info['savename'];
        }else{
             $res['messsge']=$upload->getError();
            $res['result_code'] = 101;
        }
        $this->ajaxReturn($res);
    }
}